package com.example.simpleredis.controller;

import com.example.simpleredis.entity.User;
import com.example.simpleredis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhangs
 * @version v1.0
 * @decription 前端控制器
 * @date 2021/4/7 13:35
 **/
@RestController
public class UserController {
    private UserService userService;

    @Autowired
    public void setUserService(final UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/user/list")
    public List<User> findAll() {
        return userService.findAll();
    }

    @GetMapping("/user/save")
    public User save(User user) {
        return userService.saveUser(user);
    }

    @GetMapping("/user/updatePassword")
    public int updatePassword(Long id, String password) {
        return userService.updatePassword(id, password);
    }

    @GetMapping("/user/{id}")
    public User findOne(@PathVariable("id") Long id) {
        return userService.findOne(id);
    }
}